import 'package:flutter/material.dart';
import '../config/app_theme.dart';

/// 底部导航栏
class BottomNavBar extends StatelessWidget {
  final int currentIndex;
  final Function(int) onTap;
  
  const BottomNavBar({
    super.key,
    required this.currentIndex,
    required this.onTap,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        color: AppTheme.bgCard,
        border: Border(
          top: BorderSide(
            color: AppTheme.borderColor.withOpacity(0.3),
            width: 0.5,
          ),
        ),
      ),
      child: SafeArea(
        child: SizedBox(
          height: 64,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: [
              _buildNavItem(
                index: 0,
                assetPath: 'assets/images/home.png',
                label: '首页',
              ),
              _buildNavItem(
                index: 1,
                assetPath: 'assets/images/my.png',
                label: '自选',
              ),
            ],
          ),
        ),
      ),
    );
  }
  
  Widget _buildNavItem({
    required int index,
    IconData? icon,
    IconData? activeIcon,
    String? assetPath,
    required String label,
  }) {
    final isActive = currentIndex == index;

    Widget iconWidget;
    if (assetPath != null) {
      iconWidget = ImageIcon(
        AssetImage(assetPath),
        size: 28,
        color: isActive ? AppTheme.accentColor : AppTheme.textSecondary,
      );
    } else {
      iconWidget = Icon(
        isActive ? (activeIcon ?? icon) : icon,
        size: 28,
        color: isActive ? AppTheme.accentColor : AppTheme.textSecondary,
      );
    }

    return GestureDetector(
      onTap: () => onTap(index),
      behavior: HitTestBehavior.opaque,
      child: Container(
        padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 6),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            iconWidget,
            const SizedBox(height: 4),
            Text(
              label,
              style: TextStyle(
                fontSize: 12,
                color: isActive ? AppTheme.accentColor : AppTheme.textSecondary,
              ),
            ),
          ],
        ),
      ),
    );
  }
}

